/*
 * Copyright (c) 2025. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.portalcenter.application.das;

import cn.hallele.infrastructure.metadata.io.Page;
import cn.hallele.infrastructure.util.ObjectUtil;
import cn.hallele.ms.infrastructure.core.convertor.das.ModelDas;
import cn.hallele.ms.portalcenter.application.bo.DataDictTypeBO;
import cn.hallele.ms.portalcenter.application.bo.DataDictTypeQueryBO;
import cn.hallele.ms.portalcenter.domain.action.datadict.DataDictTypeDomainService;
import cn.hallele.ms.portalcenter.domain.domain.DataDictTypeDomain;
import cn.hallele.ms.portalcenter.domain.domain.DataDictTypeQueryDomain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * hallele_ms_configcenter
 *
 * @author anle5
 * @since 2025/1/10 23:26
 */
@Slf4j
@Component
public class DataDictTypeBDDas extends ModelDas<DataDictTypeDomainService, DataDictTypeBO, DataDictTypeDomain> {
    protected DataDictTypeBDDas(DataDictTypeDomainService option) {
        super(option);
    }

    /**
     * 获取 数据字典列表
     *
     * @param condition 查询条件
     * @return List
     */
    public Page<DataDictTypeBO> getDataDictTypes(DataDictTypeQueryBO condition) {
        return revertPage(this.option.getDataDictTypes(convertQuery(condition)));
    }

    /**
     * DataDictTypeQueryDTO 转 DataDictTypeQueryBO
     *
     * @param condition MenuQueryDTO
     * @return MenuQueryBO
     */
    private DataDictTypeQueryDomain convertQuery(DataDictTypeQueryBO condition) {
        return ObjectUtil.map(condition, d -> DataDictTypeQueryDomain.builder()
                .keywords(d.getKeywords())
                .startTime(d.getStartTime())
                .endTime(d.getEndTime())
                .pageNo(d.getPageNo())
                .pageSize(d.getPageSize())
                .name(d.getName())
                .code(d.getCode())
                .status(d.getStatus())
                .build());
    }

    /**
     * 将T转成E
     *
     * @param dataDictTypeBO 被转换者
     * @return S 转换后者
     */
    @Override
    protected DataDictTypeDomain convert(DataDictTypeBO dataDictTypeBO) {
        return ObjectUtil.map(dataDictTypeBO, d -> DataDictTypeDomain.builder()
                .id(d.getId())
                .code(d.getCode())
                .name(d.getName())
                .status(d.getStatus())
                .description(d.getDescription())
                .sort(d.getSort())
                .createBy(d.getCreateBy())
                .updateBy(d.getUpdateBy())
                .createTime(d.getCreateTime())
                .updateTime(d.getUpdateTime())
                .build());
    }

    /**
     * 将E回转陈T
     *
     * @param dataDictTypeDomain 被回转换者
     * @return S 回转换后者
     */
    @Override
    protected DataDictTypeBO revert(DataDictTypeDomain dataDictTypeDomain) {
        return ObjectUtil.map(dataDictTypeDomain, d -> DataDictTypeBO.builder()
                .id(d.getId())
                .code(d.getCode())
                .name(d.getName())
                .status(d.getStatus())
                .description(d.getDescription())
                .sort(d.getSort())
                .createBy(d.getCreateBy())
                .updateBy(d.getUpdateBy())
                .createTime(d.getCreateTime())
                .updateTime(d.getUpdateTime())
                .build());
    }
}
